/**
 *
 */
package com.actor.resources;

import com.bean.ResultBean;
import com.util.FileUtil;
import com.util.StringUitl;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

import java.io.IOException;
import java.io.StringWriter;

/**
 * @author Ltz
 */
public class FrontResActor {

    /**
     * @param args
     */
    public FrontResActor(ResultBean resultBean) {
        try {
            Velocity.init();
        } catch (Exception e) {
            System.out.println("创建Action模版失败" + e);
            return;
        }
        String tableName=resultBean.getTableBean().getTableName().split("_")[1];
        String objectComment = resultBean.getTableBean().getTableComment();
        String objectName = StringUitl.CaptureName(tableName);
        String objectParam= tableName;
        String packagePath = "config.module.front";
        VelocityContext context = new VelocityContext();
        context.put("packagePath", packagePath);
        context.put("crateTime", StringUitl.GetNowDate());
        context.put("objectName", objectName);
        context.put("objectParam", objectParam);
        context.put("objectComment", objectComment.replaceAll("表", ""));
        context.put("columns", resultBean.getTableParamBean());
        StringWriter w = new StringWriter();

        try {
            Velocity.mergeTemplate("src/main/java/com/template/resources/frontres.vm", "UTF-8", context, w);
        } catch (Exception e) {
            System.out.println("模版匹配失败: " + e);
        }

        try {
            FileUtil.creatResFile(packagePath, resultBean.getTableBean().getTableName(), ".xml", w.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
